<template>
  <view>
    <!-- 添加收货地址 -->
    <view class="btn-address" v-if="JSON.stringify(address) === '{}'">
        <button type="primary" size="mini" @click="chooseAdress">+添加收货地址</button>
    </view>
    <!-- 收货信息 -->
    <view class="address-message-box" v-else @click="chooseAdress">
      <view class="row1">
        <view class="row1-left">
          <view class="username">
             收货人：姚**
          </view>
        </view>
        <view class="row1-right">
          <view class="phone">
            电话：18666666666
          </view>
          <uni-icons type="forward" size="16"></uni-icons>
        </view>
      </view>
      <view class="row2">
        <view class="address">
          收货地址：
        </view>
        <view class="row2-right">
          <!-- 河南省郑州市中原区***小区**单元**户
           河南省郑州市中原区***小区**单元**户 河南省郑州市中原区***小区**单元**户 -->
           {{addstr}}
        </view>
      </view>
    </view>
    <image src="/static/cart_border@2x.png" class="border-address"></image>
  </view>
</template>

<script>
  import {mapState , mapMutations,mapGetters} from 'vuex'
  export default {
    name:"my-address",
    data() {
      return {
      
    };
   },
   methods:{
     ...mapMutations('m_user',['updateAddress']),
    async chooseAdress(){
    const [err , succ] =await uni.chooseAddress()
      console.log(succ);
      if(err===null&& succ.errMsg ==='chooseAddress:ok'){
        this.updateAddress(succ)
      }
     }
   },
   computed:{
     ...mapState('m_user',['address']),
    ...mapGetters('m_user',['addstr'])
   }
  }
</script>

<style lang="scss">
  .btn-address{
    height: 90px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
.border-address{
  display: block;
  width: 100%;
  height: 5px;
}
.address-message-box {
  display: flex;
  flex-direction: column;
  justify-content: center;
  font-size: 12px;
  height: 90px;
  padding: 0 5px;
  .row1{
    display: flex;
    justify-content: space-between;
    .row1-right {
      display: flex;
      justify-content: space-between;
      align-items: center;
      .phone {
        margin-right: 5px;
      }
    }
  }
  .row2 {
    display: flex;
    align-items: center;
    // justify-content: space-between;
    margin-top: 10px;
    .address {
      white-space: nowrap;
    }
  }
}
</style>